package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduForumReplyDTO;
import com.zenith.edu.po.vo.EduForumReplyVO;
import com.zenith.edu.service.EduForumReplyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/forum-reply")
@Tag(name = "论坛回复管理", description = "论坛回复管理接口")
public class EduForumReplyController {
    
    @Autowired
    private EduForumReplyService eduForumReplyService;
    
    @SecurePostMapping(value = "/createForumReply", roles = "ROLE_ADMIN", permission = "forum-reply:create")
    @Operation(summary = "创建论坛回复")
    public Result<EduForumReplyVO> createForumReply(@RequestBody EduForumReplyDTO dto) {
        EduForumReplyVO forumReplyVO = eduForumReplyService.createForumReply(dto);
        return Result.success(forumReplyVO);
    }
    
    @SecurePostMapping(value = "/getForumReplyById/{id}", roles = "ROLE_ADMIN", permission = "forum-reply:read")
    @Operation(summary = "根据ID获取论坛回复详情")
    public Result<EduForumReplyVO> getForumReplyById(@PathVariable Long id) {
        EduForumReplyVO forumReplyVO = eduForumReplyService.getForumReplyById(id);
        if (forumReplyVO == null) {
            return Result.fail("论坛回复不存在");
        }
        return Result.success(forumReplyVO);
    }
    
    @SecurePostMapping(value = "/updateForumReply", roles = "ROLE_ADMIN", permission = "forum-reply:update")
    @Operation(summary = "更新论坛回复信息")
    public Result<EduForumReplyVO> updateForumReply(@RequestBody EduForumReplyDTO dto) {
        EduForumReplyVO forumReplyVO = eduForumReplyService.updateForumReply(dto);
        return Result.success(forumReplyVO);
    }
    
    @SecurePostMapping(value = "/deleteForumReply/{id}", roles = "ROLE_ADMIN", permission = "forum-reply:delete")
    @Operation(summary = "删除指定论坛回复")
    public Result<Void> deleteForumReply(@PathVariable Long id) {
        boolean result = eduForumReplyService.deleteForumReply(id);
        if (!result) {
            return Result.fail("论坛回复删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getForumReplyList", roles = "ROLE_ADMIN", permission = "forum-reply:read")
    @Operation(summary = "获取论坛回复列表")
    public Result<List<EduForumReplyVO>> getForumReplyList() {
        List<EduForumReplyVO> forumReplyList = eduForumReplyService.getForumReplyList();
        return Result.success(forumReplyList);
    }
}